package lol.clann.minecraft.springboot.plugin.bukkit.command;

import lol.clann.minecraft.springboot.api.annotation.command.CommandDefine;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author pyz
 * @date 2019/5/6 10:59 PM
 */
@Slf4j
@Component
public class CommandHook implements BeanPostProcessor {
    @Getter
    private List<Object> commands = new ArrayList<>();

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (AnnotationUtils.findAnnotation(ClassUtils.getUserClass(bean), CommandDefine.class) != null) {
            commands.add(bean);
        }
        return bean;
    }
}
